package com.fatgirl.core
{
	import flash.utils.getQualifiedClassName;
	
	import com.fatgirl.utils.binding.DataBinding;
	import com.fatgirl.utils.binding.MetaData;

	/**
	 * 自动绑定数据的 中介者 基类 
	 * @author iceman
	 * 
	 */
	public class Mediator
	{
		private var m_cName:String;
		private var m_bindDataList:Vector.<MediatorBindData>;
		public function Mediator()
		{
			
			
		}
		/**
		 * 所有初始化过程 
		 * 
		 */
		internal function initBinding():void
		{
			m_cName = getQualifiedClassName(this);
			m_bindDataList = MediatorBindFactory.getInstance().getBindData(m_cName);
			if(m_bindDataList)
			{
				for(var i:int = 0;i<m_bindDataList.length;i++)
				{
					var t_obj:Object = this;
					var t_arr:Array = m_bindDataList[i].obj.split(".");
					if(t_arr && t_arr.length>1)
					{
						for(var j:int = 1;j<t_arr.length;j++) t_obj = getValue(t_obj,t_arr[j]);
					}
					var t_data:MetaData = MediatorBindFactory.getInstance().getMetaFactory().getMetaData(m_bindDataList[i].data);
					DataBinding.binding(t_obj,m_bindDataList[i].objPro,t_data,m_bindDataList[i].dataPro);
				}
			}
		}
		private function getValue(_obj:Object,_key:String):Object
		{
			return _obj[_key];
		}
	}
}